package com.wangshouyu.mp.system.token;

import com.wangshouyu.mp.base.constant.UrlConstant;
import com.wangshouyu.mp.base.request.HttpMethod;
import com.wangshouyu.mp.base.request.MpClient;

import java.text.MessageFormat;

/**
 * @author 王守钰
 * @date 2020年08月16日 02:26
 * @description: 认证AccessToken工具
 */
public class AuthAccessTokenHandler {

    private AuthAccessTokenHandler(){}

    /**
     * 认证accessToken 获取
     * @param appId
     * @param secret
     * @param code
     * @return
     */
    public static AuthAccessToken authAccessToken(MpClient client, String appId, String secret, String code){
        String url = MessageFormat.format(UrlConstant.GET_OAUTH_ACCESS_TOKEN_URL, appId,secret,code);
        try {
            return client.request(HttpMethod.GET, url, AuthAccessToken.class);
        } catch (Exception e) {
            throw new AuthAccessTokenException(e);
        }

    }
}
